<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--宴会管理页面--%>
<html>
<head>
    <link rel="stylesheet" href="../static/layui/css/layui.css">
    <style>
        * {
            font-size: 12px;
        }

        .layui-table-page {
            text-align: center;
        }

        .layui-icon {
            margin-top: 5px;
        }

        .layui-input-block .layui-icon {
            margin-top: 0px;
        }

        .layui-table-view {
            border: none;
            margin: 0;
        }

        .layui-table-tool {
            background-color: transparent;
            /*color: ;*/
        }

        .layui-panel {
            border-radius: 5px;
        }

        .fade-in-left {
            animation: fade-in-left 0.6s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
        }

        @keyframes fade-in-left {
            0% {
                transform: translateX(-50px);
                opacity: 0;
            }
            100% {
                transform: translateX(0);
                opacity: 1;
            }
        }

        .fName {
            color: #01AAED;
        }

        .fName:hover {
            text-decoration: underline;
            color: #01AAED;
        }

        .layui-table-cell {
            /*overflow: visible;*/
            width: 177px;
        }

        /*使列表框与表格单元格重合*/
        td .layui-form-select {
            margin-top: -10px;
            margin-left: -15px;
            margin-right: -15px;
        }

        /*#attendInfo .layui-table {
            margin: 0 !important;
        }*/

        body .demo-class .layui-layer-title {
            background: #c00;
            color: #fff;
            border: none;
        }

        body .layer-ext-myskin .layui-layer-content {
            overflow: visible;
        }

        .layui-table-body {
            overflow: visible;
        }

        .typeFind input {
            height: 32px;
        }

        .header {
            position: absolute;
            z-index: 10000;
            top: 5px;
            left: 10px;
            display: none;
        }

        .header .layui-form-item {
            margin: 0;
        }

        #feastType + .layui-form-select > .layui-select-title > .layui-input {
            height: 30px;
        }

        /*.my-skin .layui-layer-btn .layui-layer-btn0{
            background-color: #84c101;
            border: 1px solid #84c101;
            color: #FFF;
        }*/
    </style>
</head>

<%--隐藏表单用于页面层显示--%>
<div id="form" class="layui-row" style="display: none">
    <div class="layui-col-md11" style="padding-top: 8px">
        <form id="formBox" class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">宴会名</label>
                <div class="layui-input-block">
                    <input type="text" name="aFeastName" required lay-verify="required" placeholder="请输入宴会名称"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">宴会类型</label>
                <div class="layui-input-inline">
                    <select class="city" name="aFeastType" lay-verify="required">
                    </select>
                </div>

                <div class="layui-form-mid">宴会日期</div>

                <div class="layui-input-inline">
                    <input type="text" readonly placeholder="宴会日期" id="date" name="aFeastDate" required
                           lay-verify="required" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">宴会预算</label>
                <div class="layui-input-block">
                    <input id="feastCost" type="number" name="aFeastCost" required lay-verify="required"
                           placeholder="请输入金额" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">地址</label>
                <div class="layui-input-block">
                    <input id="addressIn" type="text" name="aFeastAddress" required lay-verify="required"
                           placeholder="请输入地址"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <%--                <button type="button" style="position: absolute; top: 0px;right: 20px;z-index: 100;" class="layui-btn">1</button>--%>
                <div class="layui-input-block fade-in-left" id="mapBox" style="height: 300px;"></div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button style="font-size: 12px" class="layui-btn" lay-submit lay-filter="addfeast">立即提交</button>
                    <button style="font-size: 12px" type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
<div id="updateform" class="layui-row" style="display: none">
    <div class="layui-col-md11" style="padding-top: 8px">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">宴会名</label>
                <div class="layui-input-block">
                    <input type="text" id="uFeastName" name="uFeastName" required lay-verify="required"
                           placeholder="请输入宴会名称"
                           autocomplete="off" class="layui-input">
                    <input type="text" style="display: none" name="uid" id="uid">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">宴会类型</label>
                <div class="layui-input-inline">
                    <select class="city" name="feastType" id="city" lay-verify="required">
                    </select>
                </div>

                <div class="layui-form-mid">宴会日期</div>

                <div class="layui-input-inline">
                    <input type="text" id="uDate" readonly placeholder="宴会日期" name="uDate" required class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">宴会预算</label>
                <div class="layui-input-block">
                    <input type="number" id="uCost" name="uCost" required lay-verify="required" placeholder="请输入金额"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">地址</label>
                <div class="layui-input-block">
                    <input type="text" id="uAddress" name="uAddress" required lay-verify="required" placeholder="请输入地址"
                           autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button style="font-size: 12px" class="layui-btn" lay-submit lay-filter="udfeast">立即提交</button>
                </div>
            </div>
        </form>
    </div>
</div>
<div id="attendInfo" class="layui-row" style="display: none">
    <div class="layui-col-md12" style="padding: 0px 5px">
        <div class="layui-form-item fade-in-left" id="attendInfo_top"
             style="display: none;margin-top: 15px;margin-bottom: 0px">
            <div style="margin-left: 10px" class="layui-form-mid">宴会名</div>
            <div class="layui-input-inline">
                <input type="text" disabled id="feastTitle" required readonly lay-verify="required" autocomplete="off"
                       class="layui-input">
            </div>

            <div class="layui-form-mid">合计礼金</div>

            <div class="layui-input-inline">
                <input type="text" disabled id="sumGift" required readonly lay-verify="required" autocomplete="off"
                       class="layui-input">
            </div>
        </div>

        <table lay-filter="attendTab" class="layui-table fade-in-left" id="attendInfoTab"></table>
    </div>
</div>
<div id="reltype" class="layui-row" style="display:none;">
    <div class="layui-col-md12" style="padding: 20px 20px">

        <form class="layui-form" action="">
            <div class="layui-form-item" style="margin: 0 auto;">
                <div class="layui-form-mid">关系类型</div>
                <div class="layui-input-inline">
                    <select lay-filter="relType" class="seleRelType" lay-verify="required">
                    </select>
                </div>
            </div>
        </form>
    </div>
</div>

<div id="attDate" class="layui-row" style="display: none">
    <div class="layui-col-md12" style="padding: 20px 20px">
        <form class="layui-form" action="">
            <div class="layui-form-item" style="margin: 0 auto;">
                <div class="layui-form-mid">参会日期</div>
                <div class="layui-input-inline">
                    <input type="text" readonly placeholder="参会日期" id="aDate" name="aFeastDate" required
                           lay-verify="required" class="layui-input">
                </div>
            </div>
        </form>
    </div>
</div>
<div id="delFeast" class="layui-row" style="display:none;">
    <div class="layui-col-md12" style="padding: 20px 20px">
        <i class="layui-icon layui-icon-tips" style="color: orangered;font-size: 30px;"></i>
        <p style='display: inline-block;color: #e52b00;font-size: 12px;vertical-align: super;text-indent: 5px'>删除此宴会，将会删除宴会的全部参会人!</p>
        <div style="height: 30px;margin-top: 20px;padding-left: 110px">
            <button class="layui-btn layui-btn-sm" id="del_feast_ok" style="width: 70px;font-size: 12px;">确定(5)</button>
            <button class="layui-btn layui-btn-primary layui-btn-sm" id="del_feast_cancel" style="width: 70px;font-size: 12px;float: right">取消</button>
        </div>
    </div>
    <%--啊是大--%>
</div>

<body class="fade-in-left" style="padding: 8px">
<div class="layui-row">
    <div class="layui-col-md12">
        <div class="layui-panel">
            <div class="header fade-in-left">
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                        <div class="layui-input-inline" style="width: auto;padding-top: 5px;margin-right: 20px">
                            <button type="button" class="layui-btn add layui-btn-sm">
                                <i class="layui-icon layui-icon-add-circle"></i>
                                添加
                            </button>
                        </div>

                        <div class="layui-input-inline" style="width: auto;padding-top: 5px;">
                            <input type="text" placeholder="请输入宴会名" id="findFName" style="height: 30px;"
                                   class="layui-input">
                        </div>

                        <div class="layui-form-mid layui-word-aux">根据宴会类型</div>

                        <div class="layui-input-inline" style="width: auto;padding-top: 5px;">
                            <select class="city" id="feastType" lay-filter=""
                                    lay-verify="required"></select>
                        </div>

                        <div class="layui-form-mid layui-word-aux">根据日期</div>

                        <div class="layui-input-inline" style="width: auto;padding-top: 5px;margin-right: 3px">
                            <input type="text" style="height: 30px;" id="fdate" readonly lay-verify="required" placeholder="选择日期"
                                   autocomplete="off" class="layui-input">
                        </div>

                        <div class="layui-input-inline" style="width: auto;padding-top: 5px;">
                            <button type="button" id="searchFeast" class="layui-btn layui-btn-primary layui-btn-sm">
                                <i class="layui-icon layui-icon-search"></i>
                            </button>
                        </div>
                    </div>
                </form>
            </div>

            <table id="feastData" lay-filter="test"></table>
        </div>
    </div>
</div>

<script type="text/html" id="titleTpl">
    <a href="javascript:void(0);" class="fName">{{d.feastName}}</a>
</script>
<script type="text/html" id="toolbar">
    <%--<button type="button" style="display: none" class="layui-btn add layui-btn-sm fade-in-left">
        <i class="layui-icon layui-icon-add-circle"></i>
        添加
    </button>

    <div id="find" style="display: none;margin-left: 10px">
        <div class="layui-input-inline">
            <input style="height: 30px;" type="text" placeholder="请输入宴会名" id="findFName" class="layui-input">
        </div>

        <button type="button" id="searchFeast" class="layui-btn layui-btn layui-btn-sm">
            <i class="layui-icon layui-icon-search"></i>
        </button>
    </div>--%>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/html" id="appentDel">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script src="../static/bootstrap-dist/js/jquery-3.5.1.js"></script>
<script src="../static/layui/layui.js"></script>
<script type="text/javascript"
        src="https://api.map.baidu.com/api?v=1.0&type=webgl&ak=TuOFOWiPofmgWscM6GEMT4l22ZDv88DP">
</script>
<script !src="">
    $(function () {
        layui.use(['table', 'layer', 'laydate', 'form'], function () {
            let table = layui.table;
            let layer = layui.layer;
            let laydate = layui.laydate;
            let form = layui.form;

            let tableIns = table.render({
                elem: '#feastData',
                height: 630,
                id: 'diskId',
                url: 'feast',
                method: 'post',
                page: true,
                limits: [1, 5, 10, 20],
                limit: 20,
                toolbar: '#toolbar',
                defaultToolbar: ['filter', 'exports'],
                text: {
                    none: '真的没了'
                },
                title: '宴会信息表',
                parseData: function (res) {
                    return {
                        "code": 0,
                        "msg": "",
                        "count": res.totalCount,
                        "data": res.info
                    }
                },
                done: function () {
                    $(".header").show();
                },
                cols: [[
                    {type: 'numbers', title: '序号', fixed: 'left'},
                    // {field: 'id', title: 'ID', sort: true, fixed: 'left'}
                    , {event: 'onfName', templet: '#titleTpl', width: 177, title: '宴会名'}
                    , {field: 'feastDate', title: '日期'}
                    , {field: 'feastAddress', title: '地址'}
                    , {field: 'feastCost', style: 'color: goldenrod;', sort: true, title: '预算'}
                    , {field: 'typeName', title: '宴会'}
                    , {field: 'userName', title: '用户名'}
                    , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150}
                ]]
            });
            let appendTab;

            let feast_id;
            table.on('tool(test)', function (obj) {
                let data = obj.data;
                let layEvent = obj.event;
                if (layEvent === 'edit') { //查看
                    layer.open({
                        title: ['更新宴会', 'color:#333;font-size:13px;'],
                        type: 1,
                        content: $('#updateform'),
                        area: '700px',
                        maxmin: true
                    })

                    $("#uid").val(data.id);
                    $("#uFeastName").val(data.feastName);
                    $("#uAddress").val(data.feastAddress);
                    $("#uCost").val(data.feastCost);
                    $("#uDate").val(data.feastDate);

                    for (let i = 0; i < $("#city option").length; i++) {
                        if ($("#city option").eq(i).val() == data.feastType) {
                            $("#city option").eq(i).attr("selected", "selected")
                        } else {
                            $("#city option").eq(i).removeAttr("selected")
                        }
                    }

                    form.render("select");
                    // layer.alert("编辑" + data.id + "/" + data.feastName + "/" + tr);
                } else if (layEvent === 'del') {
                    $("#del_feast_ok").text("确定(5)")
                    $("#del_feast_ok").addClass("layui-btn-disabled");
                    $("#del_feast_ok").attr("disabled", "disabled");

                    let time = 5;
                    let si = setInterval(function () {
                        time -= 1;
                        $("#del_feast_ok").text("确定" + "(" + time + ")")
                        if (time == 0) {
                            $("#del_feast_ok").removeClass("layui-btn-disabled");
                            $("#del_feast_ok").removeAttr("disabled");
                            $("#del_feast_ok").text("确定");
                            clearInterval(si);
                        }
                    }, 1000);

                    layer.open({
                        title: ['删除宴会', 'color:#333;font-size:13px;'],
                        type: 1,
                        content: $('#delFeast'),
                        cancel: function(){
                            time = 5;
                            clearInterval(si);
                        }
                    })

                    //删除按钮事件
                    $("#del_feast_ok").click(function (){
                        layer.closeAll();
                        if (data.id != 0){
                            console.log(data.id);
                            let index;
                            $.ajax({
                                url: "feast",
                                method: "post",
                                dataType: "text",
                                data: {
                                    "opr": "del",
                                    "fId": data.id
                                },
                                beforeSend: function () {
                                    index = layer.load(3);
                                },
                                complete: function () {
                                    layer.close(index);
                                },
                                success: function (data) {
                                    if (data == "true") {
                                        layer.alert('删除成功', {
                                            icon: 1
                                        }, function (index) {
                                            layer.closeAll();
                                            tableIns.reload();
                                        });
                                    } else {
                                        layer.alert('删除失败,请联系管理员');
                                    }
                                },
                                error: function () {
                                }
                            })
                        }
                        data.id = 0;
                    });
                    //取消按钮事件
                    $("#del_feast_cancel").click(function (){
                        time = 5;
                        clearInterval(si);
                        layer.closeAll();
                        data.id = 0;
                    });

                    // 啊是大
                    /*let content = "<p style='color: #e52b00'>删除此宴会，将会删除宴会的全部参会人!</p>"

                    layer.confirm(content,{
                        title : ['删除宴会','color:#333;font-size:13px;'],
                        icon: 3,
                        skin : 'my-skin',
                        btn : ['确定', '取消']
                    },
                    function (index){
                        layer.alert('确定');
                    }
                    )*/

                } else if (layEvent === 'onfName') {
                    feast_id = data.id;
                    calcGift(feast_id, layer);

                    appendTab = table.render({
                        elem: '#attendInfoTab'
                        , url: 'attendPeople'
                        , where: {
                            opr: 'getAttendPeople',
                            feastId: data.id
                        }
                        , even: true
                        , method: 'post'
                        , parseData: function (res) {
                            return {
                                "code": 0,
                                "msg": "",
                                "count": res.length,
                                "data": res
                            }
                        }
                        // , totalRow: true
                        , text: {
                            none: '此宴会还没人参加'
                        }
                        , done: function (res, curr, count) {
                            $("#attendInfo_top").show();
                            $("#attendInfo table").css("width", "100%");
                            $("#attendInfo .layui-table-box").css("border", "0.5px solid rgba(0,0,0,0.05)");
                        }
                        , cols: [[
                            {
                                field: 'attendPeople',
                                style: 'color: black;',
                                title: '姓名',
                                edit: 'text',
                                totalRowText: '合计：'
                            }
                            , {field: 'attendDate', event: 'attendDate', title: '参会日期'}
                            , {field: 'gift', style: 'color: goldenrod;', title: '礼金', /*totalRow: true, */edit: 'text'}
                            , {field: 'relationType', event: 'relType', title: '关系'}
                            , {field: 'note', title: '备注', edit: 'text'}
                            , {title: '操作', toolbar: '#appentDel'}
                        ]]
                    });

                    $("#feastTitle").val(data.feastName);
                    layer.open({
                        title: ['宴会详情', 'color:#333;font-size:13px;'],
                        type: 1,
                        content: $('#attendInfo'),
                        area: ['1200px', '650px'],
                        skin: 'layui-layer-molv',
                        closeBtn: 1,
                        resize: false,
                        shadeClose: true,
                        maxmin: true,
                        end: function () {
                            $("#attendInfo_top").hide();
                        }
                    });

                    // layer.alert(data.id + "/" + data.feastName);
                }
            });

            //监听单元格编辑
            table.on('edit(attendTab)', function (obj) {
                let value = obj.value //得到修改后的值
                    , data = obj.data //得到所在行所有键值
                    , field = obj.field; //得到字段

                let index;
                $.ajax({
                    url: "attendPeople",
                    method: "post",
                    data: {
                        "field": field,
                        "value": value,
                        "id": data.id,
                        "opr": "editCell"
                    },
                    beforeSend: function () {
                        index = layer.load(2); //换了种风格
                    },
                    complete: function () {
                        layer.close(index);
                    },
                    success: function (data) {
                        if (data == "true") {
                            layer.msg('修改成功');
                            appendTab.reload();
                        } else {
                            layer.msg('修改失败');
                            appendTab.reload();
                        }
                        calcGift(feast_id, layer);
                    },
                    error: function () {
                        layer.msg('修改失败');
                    }
                })
                // layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
            });

            /*获取关系类型*/
            $.ajax({
                url: "rType",
                method: "post",
                data: {
                    "opr": "list"
                },
                dataType: "json",
                success: function (data) {
                    $(".seleRelType").empty();
                    for (let i = 0; i < data.length; i++) {
                        $(".seleRelType").append("<option value=" + data[i].id + ">" + data[i].relationType + "</option>");
                    }

                    form.render("select");
                },
                error: function () {
                    layer.alert("关系请求失败");
                }
            })

            table.on('tool(attendTab)', function (obj) {
                let data = obj.data;
                let layEvent = obj.event;

                console.log(obj.data);

                let index;
                if (layEvent === 'relType') {
                    index = layer.open({
                        title: ['修改关系', 'color:#333;font-size:13px;'],
                        skin: 'layer-ext-myskin',
                        type: 1,
                        content: $('#reltype')
                    });

                    for (let i = 0; i < $(".seleRelType option").length; i++) {
                        if ($(".seleRelType option").eq(i).val() == data.relationID) {
                            $(".seleRelType option").eq(i).attr("selected", "selected")
                        } else {
                            $(".seleRelType option").eq(i).removeAttr("selected")
                        }
                    }
                    form.render("select");
                } else if (layEvent === 'attendDate') {
                    $("#aDate").val(data.attendDate)

                    let index1 = layer.open({
                        title: ['修改日期', 'color:#333;font-size:13px;'],
                        skin: 'layer-ext-myskin',
                        type: 1,
                        content: $('#attDate')
                    });
                    setIndex(index1);

                    laydate.render({
                        elem: '#aDate',
                        type: 'date',
                        done: function (value) {
                            layer.close(getIndex());
                            let i;
                            $.ajax({
                                url: "attendPeople",
                                method: "post",
                                data: {
                                    "opr": "editCell",
                                    "value": value,
                                    "field": "attendDate",
                                    "id": data.id
                                },
                                beforeSend: function () {
                                    i = layer.load(2); //换了种风格
                                },
                                complete: function () {
                                    layer.close(i);
                                },
                                success: function (res) {
                                    if (res == "true") {
                                        layer.msg('修改成功');
                                    } else {
                                        layer.msg('修改失败');
                                    }
                                    appendTab.reload();
                                }
                            })
                        }
                    });

                } else if (layEvent === 'del') {
                    layer.confirm('确定删除吗?', {icon: 3, title: '提示'}, function (index) {
                        let i;
                        $.ajax({
                            url: "attendPeople",
                            method: "post",
                            data: {
                                "opr": "del",
                                "id": data.id,
                            },
                            beforeSend: function () {
                                i = layer.load(2); //换了种风格
                            },
                            complete: function () {
                                layer.close(i);
                            },
                            success: function (d) {
                                if (d == "true") {
                                    layer.msg("删除成功");
                                } else {
                                    layer.msg("删除失败");
                                }
                                appendTab.reload();
                                calcGift(feast_id, layer);
                            },
                            error: function () {

                            }
                        })

                        layer.close(index);
                    });
                }

                form.on('select(relType)', function (d) {
                    layer.close(index);
                    let i;
                    $.ajax({
                        url: "attendPeople",
                        method: "post",
                        data: {
                            "opr": "editCell",
                            "value": d.value,
                            "field": "relationID",
                            "id": data.id
                        },
                        beforeSend: function () {
                            i = layer.load(2); //换了种风格
                        },
                        complete: function () {
                            layer.close(i);
                        },
                        success: function (res) {
                            if (res == "true") {
                                layer.msg('修改成功');
                            } else {
                                layer.msg('修改失败');
                            }
                            appendTab.reload();
                        }
                    })
                });

            })

            $("body").on("click", ".add", function () {
                let index = layer.open({
                    title: ['添加宴会', 'color:#333;font-size:13px;'],
                    type: 1,
                    content: $('#form'),
                    area: '700px',
                    closeBtn: 1,
                    resize: false,
                    maxmin: true,
                    shadeClose: true,
                    end: function () {
                        $("#formBox")[0].reset();
                    }
                });

                layer.full(index);
            });

            /*加载宴会类型*/
            $.ajax({
                url: "feastType",
                method: "post",
                dataType: "json",
                success: function (data) {
                    $(".city").empty();
                    $(".city").append("<option value=''>请选择宴会</option>");
                    for (let i = 0; i < data.length; i++) {
                        $(".city").append("<option value=" + data[i].id + ">" + data[i].typeName + "</option>");
                    }
                    form.render("select");
                },
                error: function () {
                    layer.alert("宴会类型请求失败");
                }
            });

            $("body").on("click", "#searchFeast", function () {
                table.reload('diskId', {
                    methods: "post"
                    , request: {
                        pageName: 'page' //页码的参数名称，默认：page
                        , limitName: 'limit' //每页数据量的参数名，默认：limit
                    }
                    , where: {
                        opr: "findByName",
                        fName: $("#findFName").val(),
                        fType: $("#feastType").val(),
                        fDate: $("#fdate").val(),
                    }
                    , page: {
                        curr: 1
                    },
                });
            });

            /*添加表单的submit事件*/
            form.on('submit(addfeast)', function (data) {
                let index;
                $.ajax({
                    url: "feast",
                    method: "post",
                    dataType: "text",
                    data: {
                        "opr": "add",
                        "name": data.field.aFeastName,
                        "type": data.field.aFeastType,
                        "date": data.field.aFeastDate,
                        "cost": data.field.aFeastCost,
                        "address": data.field.aFeastAddress
                    },

                    beforeSend: function () {
                        index = layer.load(3); //换了种风格
                    },
                    complete: function () {
                        layer.close(index);
                    },
                    success: function (data) {
                        if (data == "true") {
                            layer.alert('添加成功', {
                                icon: 1
                            }, function (index) {
                                layer.closeAll();
                                tableIns.reload();
                            });
                        } else {
                            layer.alert('添加失败,请联系管理员');
                        }
                    },
                    error: function () {
                    }
                })

                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });

            /*修改表单的submit事件*/
            form.on('submit(udfeast)', function (data) {
                let index;
                $.ajax({
                    url: "feast",
                    method: "post",
                    dataType: "text",
                    data: {
                        "opr": "edit",
                        "fId": data.field.uid,
                        "fName": data.field.uFeastName,
                        "fType": data.field.feastType,
                        "fDate": data.field.uDate,
                        "cost": data.field.uCost,
                        "address": data.field.uAddress
                    },
                    beforeSend: function () {
                        index = layer.load(3);
                    },
                    complete: function () {
                        layer.close(index);
                    },
                    success: function (data) {
                        if (data == "true") {
                            layer.alert('修改完成', {
                                icon: 1
                            }, function (index) {
                                layer.closeAll();
                                tableIns.reload();
                            });
                        } else {
                            layer.alert('修改失败,请联系管理员');
                        }
                    },
                    error: function () {
                    }
                })


                return false;
            });

            $("#addressIn").blur(function () {
                var myGeo = new BMapGL.Geocoder();
                // 将地址解析结果显示在地图上，并调整地图视野
                myGeo.getPoint($("#addressIn").val(), function (point) {
                    if (point) {
                        map.centerAndZoom(point, 16);
                        map.addOverlay(new BMapGL.Marker(point, {title: $("#addressIn").val()}))
                    } else {
                        layer.tips('您选择的地址没有解析到结果！', '#addressIn');
                    }
                }, $("#addressIn").val());

            });

            laydate.render({
                elem: '#date',
                type: 'date'
            });

            laydate.render({
                elem: '#uDate',
                type: 'date'
            });

            laydate.render({
                elem: '#fdate',
                type: 'date',
                range: '~'
            });
        });
    });

    let indexs;

    function setIndex(index) {
        indexs = index;
    }

    function getIndex() {
        return indexs;
    }

    function calcGift(feast_id, layer) {
        let index;
        $.ajax({
            url: "attendPeople",
            data: {
                "opr": "calcGift",
                "feastId": feast_id
            },
            beforeSend: function () {
                index = layer.load(2); //换了种风格
            },
            complete: function () {
                layer.close(index);
            },
            success: function (data) {
                $("#sumGift").val(data);
            }
        })
    }

    /*百度地图*/
    var map = new BMapGL.Map("mapBox");
    // 创建地图实例
    var point = new BMapGL.Point(113.61177264985935, 34.74587748593553);
    // 创建点坐标
    map.centerAndZoom(point, 15);
    // 初始化地图，设置中心点坐标和地图级别
    var scaleCtrl = new BMapGL.ScaleControl();  // 添加比例尺控件
    map.addControl(scaleCtrl);
    var zoomCtrl = new BMapGL.ZoomControl();  // 添加缩放控件
    map.addControl(zoomCtrl);
    var cityCtrl = new BMapGL.CityListControl();  // 添加城市列表控件
    map.enableScrollWheelZoom(true);
    map.addControl(cityCtrl);
    map.addEventListener('click', function (e) {
        var point = new BMapGL.Point(e.latlng.lng, e.latlng.lat);
        var marker = new BMapGL.Marker(point);        // 创建标注
        map.addOverlay(marker);
        console.log('点击位置经纬度：' + e.latlng.lng + ',' + e.latlng.lat);
        map.clearOverlays();
        var point = new BMapGL.Point(e.latlng.lng, e.latlng.lat);
        var marker = new BMapGL.Marker(point);        // 创建标注
        map.addOverlay(marker);
        console.log('点击位置经纬度：' + e.latlng.lng + ',' + e.latlng.lat);
        let address;
        let gc = new BMapGL.Geocoder();
        gc.getLocation(point, function (rs) {
            var addComp = rs.addressComponents;
            address = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber;
            console.log(address);
            $("#addressIn").val(address + "附近");
        });

    });
    $("#addressIn").blur(function () {
        map.clearOverlays();
        var myGeo = new BMapGL.Geocoder();
        // 将地址解析结果显示在地图上，并调整地图视野
        myGeo.getPoint($("#addressIn").val(), function (point) {
            if (point) {
                map.centerAndZoom(point, 16);
                map.addOverlay(new BMapGL.Marker(point, {title: $("#addressIn").val()}))
            } else {
                alert('您选择的地址没有解析到结果！');
            }
        }, $("#address").val())
    });


</script>
</body>
</html>
